package com.salary.service;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Filter {
	private static String[] companyArray = null;
	private static String[] propertyArray = null;
	private static String tax = null;

	public Filter(String filepath) {
		readCondtion(filepath);
	}

	public void readCondtion(String filepath) {
		try {
			BufferedReader in = new BufferedReader(new FileReader(filepath));
			byte[] buf = new byte[1024];
			StringBuffer sb = new StringBuffer();
			String line = null;
			while ((line = in.readLine()) != null) {
				sb.append(line);
				// sb.append(new String(buf, "UTF-8"));
				buf = new byte[1024];// 重新生成，避免和上次读取的数据重复
			}
			String source = sb.toString().trim();
			// 去除换行符
			Pattern p = Pattern.compile("\t|\r|\n|\13");
			Matcher m;
			m = p.matcher(source);
			String s = m.replaceAll("");
			String str[] = s.split("#");
			String str1 = str[0];
			String str2 = str[1];

			if (str.length == 3) {
				tax = str[2];
			}
			companyArray = str1.split(",");
			propertyArray = str2.split(",");
			in.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static String[] getCompanyArray() {
		return companyArray;
	}

	public static String[] getPropertyArray() {
		return propertyArray;
	}

	public static String getTax() {
		return tax;
	}

}
